//
//  ViewController.m
//  10508
//
//  Created by student on 16/2/20.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)packageWithFirst:(int)first andLast:(int)last andPicName:(NSString*)pic andTimer:(int)timer
{
    NSMutableArray *mArr = [[NSMutableArray alloc] init];
    for (int i=first; i<=last; i++)
    {
        NSString *picName;
        if(i<10)
        {
            picName = [NSString stringWithFormat:@"%@_0%i",pic,i];
        }
        else
        {
            picName = [NSString stringWithFormat:@"%@_%i",pic,i];
        }
        UIImage *image = [UIImage imageNamed:picName];
        [mArr addObject:image];
    }
    self.imageView.animationImages = mArr;
    self.imageView.animationDuration = timer;
    self.imageView.animationRepeatCount = 1;
    [self.imageView startAnimating];
}
- (IBAction)cymbalBtn:(id)sender {
    [self packageWithFirst:0 andLast:12 andPicName:@"cymbal" andTimer:1];
}
- (IBAction)drink:(id)sender {
    [self packageWithFirst:0 andLast:80 andPicName:@"drink" andTimer:5];
}
- (IBAction)eatBtn:(id)sender {
    [self packageWithFirst:0 andLast:39 andPicName:@"eat" andTimer:3];
}
- (IBAction)fartBtn:(id)sender {
    [self packageWithFirst:0 andLast:27 andPicName:@"fart" andTimer:3];
}
- (IBAction)pieBtn:(id)sender {
    [self packageWithFirst:0 andLast:23 andPicName:@"pie" andTimer:2];
}
- (IBAction)scratchBtn:(id)sender {
    [self packageWithFirst:0 andLast:55 andPicName:@"scratch" andTimer:5];
}

- (IBAction)footLeft:(id)sender {
    [self packageWithFirst:0 andLast:29 andPicName:@"footLeft" andTimer:3];
}
- (IBAction)footRight:(id)sender {
    [self packageWithFirst:0 andLast:29 andPicName:@"footRight" andTimer:3];
}
- (IBAction)knockoutBtn:(id)sender {
    [self packageWithFirst:0 andLast:80 andPicName:@"knockout" andTimer:5];
}
- (IBAction)stomach:(id)sender {
    [self packageWithFirst:0 andLast:33 andPicName:@"stomach" andTimer:3];
}
- (IBAction)angryBtn:(id)sender {
    [self packageWithFirst:0 andLast:25 andPicName:@"angry" andTimer:3];
}
@end
